package com.geek.aware;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;

@Service
@Slf4j
public class ScheduledTaskService {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        log.info("每隔五秒执行一次：{}", dateFormat.format(Calendar.getInstance().getTime()));
    }

    @Scheduled(cron = "0 42 16 ? * *")
    public void fixTimeExecution(){
        log.info("在指定时间：{} 执行", dateFormat.format(Calendar.getInstance().getTime()));
    }
}
